package com.hippo.core.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hippo.core.R
import com.hippo.core.core.ext.click
import com.hippo.core.ui.theme.ColorBody
import com.hippo.core.ui.theme.HippoTheme

@Composable
fun KayValueLayout(
    key: String,
    value: String? = null,
    rightAlign: Boolean = true,
    showArrow: Boolean = false,
    onClick: (() -> Unit)? = null
) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = Modifier
            .padding(vertical = 12.dp, horizontal = 8.dp)
            .click {
                onClick?.invoke()
            }
    ) {
        Text(
            text = key,
            style = MaterialTheme.typography.labelMedium
        )

        Text(
            text = value ?: "",
            modifier = Modifier
                .weight(1F)
                .padding(start = 20.dp),
            textAlign = if (rightAlign) TextAlign.End else TextAlign.Start,
            color = ColorBody,
            style = MaterialTheme.typography.bodySmall
        )

        if (showArrow) {
            HorizontalSpacer(10.dp)
            Image(
                painter = painterResource(id = R.mipmap.arrow_right),
                contentDescription = null,
                modifier = Modifier.size(25.dp)
            )
        }
    }
}

@Preview(showBackground = true)
@Composable
private fun KayValueLayoutPreview() {
    HippoTheme {
        KayValueLayout(
            key = "key",
            value = "value"
        )
    }
}